//École de Technologie Supérieure (ÉTS)
//LOG720 - Laboratoire 3  - Intégration de Spring + Hibernate
//Date de remise: 2011-12-13
//Auteurs:
//Jonathan Aubuchon (AUBJ18038704)
//Jeff Grenier (GREJ02098703)
//Francis Paré (PARF21038708)

package springapp.web;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.view.RedirectView;

import springapp.domain.Infraction;
import springapp.service.InfractionCommand;
import springapp.service.InfractionManager;

public class CreerInfractionController extends SimpleFormController {

	
	public ModelAndView onSubmit(Object command) throws ServletException {
		
		InfractionCommand infraction = (InfractionCommand) command;
		
		Infraction i = new Infraction();
		i.setDescription(infraction.getDescription());
		i.setNiveau(infraction.getNiveau());
		
		InfractionManager.getInstance().ajouterInfraction(i);
        return new ModelAndView(new RedirectView(getSuccessView()));
    }

    protected Object formBackingObject(HttpServletRequest request)
            throws ServletException {
    	
    	InfractionCommand infractionCommand = new InfractionCommand();
    	return infractionCommand;
    }
	
	

}
